package com.thrc.borrow.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.springframework.util.StringUtils;

public class DateUtil {

	private static final String DATE_FORMART = "yyyy-MM-dd";

	public static String converTimestampToStr(Double timestamp) {

		if (timestamp <= 0)
			return "1990-01-01";

		SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMART);
		return sdf.format(timestamp);
	}

	public static String getDateString(Date date, String format) {

		if (date == null)
			date = new Date();

		if (StringUtils.isEmpty(format))
			format = DATE_FORMART;

		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}

	public static String getDateString() {

		return getDateString(null, null);
	}
	
	/**
     * 得到几月后的时间
     *
     * @param d
     * @param month
     * @return
     */
    public static Date getMonthAfter(Date d, int month) {
        Calendar now = Calendar.getInstance();
        now.setTime(d);
        now.add(Calendar.MONTH,month);
        return now.getTime();
    }
}
